package com.zimmur.app.mocolink.manage.web.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.zimmur.app.mocolink.domain.model.GroupStyle;
import com.zimmur.app.mocolink.domain.vo.GroupStyleVo;
import com.zimmur.app.mocolink.manage.web.common.ReturnJsonEntity;
import com.zimmur.app.mocolink.manage.web.common.StatusCodeEnum;
import com.zimmur.app.mocolink.service.IGroupStyleService;

@Controller
@RequestMapping("/groupStyle")
public class GroupGoodsStyleController extends BaseController {

	@Autowired
	private IGroupStyleService groupStyleService;
	@RequestMapping("/index")
	public String index(HttpServletRequest request,ModelMap model){
		List<GroupStyleVo> styleList=groupStyleService.getAllStyle();
		model.addAttribute("styleList", styleList);
		return "/center/groupGoodsStyle/list";
	}
	@RequestMapping("/edit")
	public String edit(HttpServletRequest request,ModelMap model){
		Integer styleId = getParam("styleId", 0);
		GroupStyle groupStyle = groupStyleService.selectById(styleId);
		List<GroupStyleVo> styleList = groupStyleService.getAllStyle();
		model.addAttribute("styleList", styleList);
		model.addAttribute("groupStyle", groupStyle);
		return "/center/groupGoodsStyle/edit";
	}
	@RequestMapping("/add")
	public String add(HttpServletRequest request,ModelMap model){
		List<GroupStyleVo> list = groupStyleService.getAllStyle();
		model.addAttribute("styleList", list);
		model.addAttribute("groupStyle", new GroupStyle());
		return "/center/groupGoodsStyle/edit";
	}
	@ResponseBody
	@RequestMapping("/save")
	public ReturnJsonEntity save(GroupStyle groupStyle){
		ReturnJsonEntity entity = new ReturnJsonEntity();
		StatusCodeEnum codeEnum = StatusCodeEnum.CODE100000;
		int flag = 0;
		if(groupStyle.getId()!=null && groupStyle.getId()>0){
			flag = groupStyleService.update(groupStyle);
		}else{
			flag = groupStyleService.add(groupStyle);
		}
		if(flag>0){
			codeEnum = StatusCodeEnum.CODE000000;	
		}
		entity.init(codeEnum);
		return entity;
	}
	@ResponseBody
	@RequestMapping("/delete")
	public ReturnJsonEntity delete(){
		ReturnJsonEntity entity = new ReturnJsonEntity();
		StatusCodeEnum codeEnum = StatusCodeEnum.CODE100000;
		Integer styleId = getParam("styleId",0);
		int flag = groupStyleService.delete(styleId);
		if(flag>0){
			codeEnum = StatusCodeEnum.CODE000000;
		}
		entity.init(codeEnum);
		return entity;
	}
}
